/**
 * Sysnet Pionner Solutions
 * @license : Under MIT, GNU
 * @document : sysnet_pioneer-loading.js
 * @created : Nov 30, 2011, 11:13:35 AM
 * @author : 006550
 * @template : created by Darkarts
 */

(function($){
//    $.debug.ajaxEffect = function(msg){
//        if(console){
//            console.log("ajaxEffect : ",msg)
//        }
//    }    
    
    $.set.ajaxEffect = {
        css:{
            
        }
        ,html:function(args){
            var set = $.extend({
                img:IMG("loading.gif")
                ,lbl:"Requesting"
            },args);
            
            return '<table class="xmb loading_control">'+
                        '<td class="xmb img">'+
//                            '<img src="asset/global/imgs/loading.gif" />'+
                            '<img src="'+set.img+'" />'+
                        '</td>'+
//                        '<td class="xmb lbl">Requesting...</td>'+
                        '<td class="xmb lbl">'+set.lbl+'</td>'+
                    '</table>';
        }
        ,stat:{
            "500":{
                lbl:"Server encountered an error!"
                ,img:IMG("warning.png")
            }
            ,"200":{
                lbl:"Successful"
                ,img:IMG("success.png")
            }
            ,"201":{
                lbl:"Requesting..."
                ,img:IMG("loading.gif")
            }
        }
        ,append:"html"
    }
    
    /***
     * ajax Effect helps on creating ajax animation.
     */
    $.fn.status = function(args){
        // initialize args and default settings
//        var debug = $.debug.ajaxEffect;
        var set =  $.set.ajaxEffect;
        var effect = {};
        
//        debug("init..")
        if(typeof(args) == "object")effect = args;
        else{
            // checks if the user wants to remote the animation.
            if(args == "remove"){
                this.find(".loading_control").remove(); return;
                con.log("removing");
            }
            // else set the parameter from the user.
            effect = set.stat[args];
        } 
        
        return this.each(function(){
           var $this = $(this);
           
           $this[set.append](set.html(effect))
        });
    }
    
})(jQuery)
